package com.wen.securitydemo1.reflet;

import java.io.FileInputStream;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Properties;

public class RefletionQuestion {


    public static void main(String[] args) throws IllegalAccessException, InvocationTargetException, InstantiationException, IOException, NoSuchMethodException, ClassNotFoundException {
        new RefletionQuestion().reflectTest();

    }

    @SuppressWarnings("${all}")
    public void reflectTest() throws ClassNotFoundException, IllegalAccessException, InstantiationException, NoSuchMethodException, InvocationTargetException, IOException {
        //获取配置文件内容
        Properties properties = new Properties();
        properties.load(new FileInputStream("src/main/resources/application.yml"));
        String classfullpath = properties.getProperty("classfullpath");
        String method = properties.getProperty("method");


        System.out.println(classfullpath + "     " + method);
        Class<?> aClass = Class.forName(classfullpath); //获取Class类的对象aClass
        Object o = aClass.newInstance();         //通过Class类型的对象aClass获取类型为Cat的对象
        System.out.println(o.getClass());
        Method methodName = aClass.getMethod(method);   //这里把方法也当做一个对象来看
        Object invoke = methodName.invoke(o);   //这里是通过方法对象传入该方法所属累的对象来进行调用
    }
}
